package com.alcatel_lucent.osp.model;

import javax.persistence.*;
import java.util.Collection;

/**
 * Created with IntelliJ IDEA.
 * User: Guoshun WU
 * Date: 13-8-23
 * Time: 下午6:12
 */

@Entity
@Table(name = "CATEGORY")
public class Category extends BaseEntity {

    private String name;
    private Collection<User> owners;
    private Collection<Type> types;
    private String mailingList;

    @Column(name = "MAILING_LIST", length = 1024, nullable = true)
    public String getMailingList() {
        return mailingList;
    }

    public void setMailingList(String mailingList) {
        this.mailingList = mailingList;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IdCategoryGenerator")
    @SequenceGenerator(name = "IdCategoryGenerator", sequenceName = "ID_CATEGORY")
    @Override
    public Long getId() {
        return super.getId();
    }

    @Column(name = "NAME")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToMany
    @JoinTable(name = "CATEGORY_USER",
            joinColumns = @JoinColumn(name = "CATEGORY_ID"),
            inverseJoinColumns = @JoinColumn(name = "USER_CSL")
    )
    public Collection<User> getOwners() {
        return owners;
    }

    public void setOwners(Collection<User> owners) {
        this.owners = owners;
    }

    @JoinTable(
            name = "CATEGORY_TYPE",
            joinColumns = @JoinColumn(name = "CATEGORY_ID"),
            inverseJoinColumns = @JoinColumn(name = "TYPE_ID")
    )
    @ManyToMany()
    public Collection<Type> getTypes() {
        return types;
    }

    public void setTypes(Collection<Type> types) {
        this.types = types;
    }
}
